package com.xm.controller;

import com.xm.common.entity.PayEntity;
import com.xm.common.entity.R;
import com.xm.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author lililiang
 * @Date 21/04/29 10:14
 * @Version 1.0
 **/
@Api(tags = "订单模块")
@RestController
@Slf4j
@RequestMapping("pay")
@RefreshScope
public class PayController {

    @Value("${server.port}")
    private String serverPort;

    /**
     * @return java.lang.String
     * @Description 打印当前端口信息并返回
     * @Author lililiang
     * @Date 14:37 21/04/29
     * @Param [id]
     **/
    @ApiOperation(value = "打印当前端口")
    @GetMapping(value = "getPay/{id}")
    public String getPay(@PathVariable("id") Integer id) {
        return "pay-getPay, serverPort: " + serverPort + "\t id:" + id;
    }

    @Resource
    private PayService payService;

    @ApiOperation(value = "查询数据库")
    @GetMapping(value = "getPayFormDataBase/{id}")
    public R getPayFormDataBase(@PathVariable("id") Long id) {
        // 业务逻辑处理正确，但是需要耗费3秒钟
//        try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
        PayEntity pay = payService.getPayFormDataBase(id);
        R r = new R();
        r.setData(pay);
        return r;
    }

}
